//
//  MessageViewController.swift
//  MySwiftProject
//
//  Created by 蓓蕾 on 2021/11/11.
//

import UIKit
import SwiftUI

class MessageViewController: UIViewController {

    var llll: UILabel!
    
    var oldcolor:(r: CGFloat,g: CGFloat,b: CGFloat,a: CGFloat)! = nil
    
    var newcolor:(r: CGFloat,g: CGFloat,b: CGFloat,a: CGFloat)! = nil
    
//    var oldcolor:UIColor!
//
//    var newcolor:UIColor!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        oldcolor = UIColor.purple.iNeedRBGA()
        
        newcolor = UIColor.red.iNeedRBGA();
        
        setUI()
    }
    
    func setUI()
    {
        let slider : UISlider = UISlider(frame: CGRect(x: 100, y: 200, width: kScreenWidth - 200, height: 30))
        self.view.addSubview(slider)
        slider.backgroundColor = UIColor.blue
//        slider.addTarget(self, action:"sliderDidChange:", for: UIControl.Event.valueChanged)
        slider.addTarget(self, action: "sliderDidChange:", for: UIControl.Event.valueChanged)
        llll = UILabel(frame: CGRect(x: 20, y: 80, width: kScreenWidth - 40, height: 20))
        llll.text = "逐渐变得原谅起来"
        llll.textColor = UIColor.purple
        llll.font = UIFont.systemFont(ofSize: 20)
        llll.textAlignment = NSTextAlignment.center
    }
    
    func sliderDidChange(slider:UISlider){
        print(slider.value)
        
        }
    
    func silderChangeValue(sender: UISlider) {
        
        let progress = CGFloat(sender.value)
        
        let R = oldcolor.r + (newcolor.r - oldcolor.r) * progress
        let G = oldcolor.g + (newcolor.g - oldcolor.g) * progress
        let B = oldcolor.b + (newcolor.b - oldcolor.b) * progress
        let A = oldcolor.a + (newcolor.a - oldcolor.a) * progress
        
        llll.textColor = UIColor(red: R, green: G, blue: B, alpha: A)
        
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
